//
//  PlayViewController.m
//  PlayDAs
//
//  Created by 周莹 on 15/12/15.
//  Copyright © 2015年 周莹. All rights reserved.
//
#import "TSPopoverController.h"
#import "TSActionSheet.h"
#import "PlayViewController.h"
#import "Colours.h"
#import "PopoverView.h"
#import "PlayTableViewCell.h"
#define IMAGEVIEW_TAG 2000
#import "SearchViewController.h"
#import "DetilVController.h"
#import "AnswerViewController.h"
#import "PuzzseViewController.h"
@interface PlayViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *topImage;

@end

@implementation PlayViewController
- (void)viewDidLoad {
    FLAdView *adView = [[FLAdView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 130)];
    adView.imageArray = @[@"jingzhun.jpg",@"hulian.jpg",@"shengqian.jpg"];
    adView.location = PageControlCenter;//设置pagecontrol的位置
    adView.currentPageColor = [UIColor redColor];//选中pagecontrol的颜色
    adView.normalColor = [UIColor yellowColor];//未选中的pagecontol的颜色
    adView.chageTime = 3.0f;//定时时间 默认3秒
    adView.flDelegate = self;//图片点击事件delegate
    [self.view addSubview:adView];
    
    
    [self  craet];
    
  
    self.title = @"玩坏广告";
    [super viewDidLoad];
    self.headTableVIew.dataSource = self;
    self.headTableVIew.delegate = self;
//    UIButton *leftB = [UIButton buttonWithType:UIButtonTypeCustom];
//    leftB.frame = CGRectMake(0, 0, 20, 18);
//    [leftB setBackgroundImage:[UIImage imageNamed:@"加号.png"] forState:UIControlStateNormal];
//    [leftB addTarget:self action:@selector(leftBDidPOP) forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftB];
    [self.headTableVIew  registerNib:[UINib nibWithNibName:@"PlayTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    UIButton *rightB = [UIButton buttonWithType:UIButtonTypeCustom];
    rightB.titleLabel.text = @"我";
    rightB.frame = CGRectMake(0, 0, 30, 30);
    [rightB setBackgroundImage:[UIImage imageNamed:@"fangdajing.png"] forState:UIControlStateNormal];
    [rightB addTarget:self action:@selector(rightBDidPOP) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightB];
    
    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
    right.titleLabel.text = @"我";
    right.frame = CGRectMake(0, 0, 30, 30);
    [right setBackgroundImage:[UIImage imageNamed:LeftB] forState:UIControlStateNormal];
    [right addTarget:self action:@selector(showActionSheet:forEvent:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:right];
}


//图片点击事件delegate

-(void)imageTaped:(UIImageView *)imageView{
    NSLog(@"imageView tag is %ld",(long)imageView.tag);
}



-(void) showActionSheet:(id)sender forEvent:(UIEvent*)event
{
    
    
    TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@"类别"];
    
    [actionSheet addButtonWithTitle:@"分享" block:^{
//        EmpViewController  *e = [[EmpViewController  alloc] init];
//        [self.navigationController  pushViewController:e  animated:YES];
    }];
    [actionSheet addButtonWithTitle:@"扫一扫" block:^{
//        FacViewController  *n = [[FacViewController  alloc] init];
//        [self.navigationController  pushViewController:n animated:YES];
    }];
    [actionSheet addButtonWithTitle:@"帮助" block:^{
//        PdViewController  *p = [[PdViewController  alloc] init];
//        [self.navigationController  pushViewController:p  animated:YES];
    }];
    
    [actionSheet addButtonWithTitle:@"反馈de" block:^{
        //        PdViewController  *p = [[PdViewController  alloc] init];
        //        [self.navigationController  pushViewController:p  animated:YES];
    }];
    actionSheet.cornerRadius = 5;
    
    [actionSheet showWithTouch:event];
    
    
    
    
}



-(void)rightBDidPOP{
    
    SearchViewController * sCV = [[SearchViewController  alloc] init];
    [self.navigationController pushViewController:sCV animated:YES];
    
    
}



//-(void)leftBDidPOP{
//    
//    CGPoint point = CGPointMake(self.view.frame.size.height, self.view.frame.size.width/5);
//    NSArray *titles = @[@"分享", @"扫一扫", @"帮助",@"反馈"];
//    PopoverView *pop = [[PopoverView alloc] initWithPoint:point titles:titles images:nil];
//    pop.selectRowAtIndex = ^(NSInteger index){
//        NSLog(@"select index:%ld", (long)index);
//    };
//    [pop show];
//    
//    
//    
//}
//

-(void)craet{

//    self.scrollView = [[UIScrollView alloc]init];
//    
//    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT );
//    
//    self.scrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
//    
//    [self.view addSubview:self.scrollView];
//    





}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cell_id =@"flag";
    
    PlayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id];
    if (cell == nil) {
        //创建cell,不能少....
        cell = [[PlayTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cell_id];
        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        
    }
    if (indexPath.row == 0) {
        cell.imageView.image= [UIImage imageNamed:@"2.jpg"];
        
        
    }else if (indexPath.row == 1){
        cell.imageView.image= [UIImage imageNamed:@"3.jpg"];
        
        
    }else if (indexPath.row == 2){
        cell.imageView.image= [UIImage imageNamed:@"第一个.jpg"];
        
        
    }
   
    
    
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        DetilVController  *vi = [[DetilVController  alloc] init];
        [self.navigationController  pushViewController:vi animated:YES];
    }
    


}







-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;

}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)answer:(UIButton *)sender {
    
    AnswerViewController * acv = [[AnswerViewController alloc] init];
    [self.navigationController  pushViewController:acv animated:YES];
    
    
    
    
}

- (IBAction)puzzle:(UIButton *)sender {
    
    PuzzseViewController *puc = [[PuzzseViewController  alloc] init];
    [self.navigationController  pushViewController:puc animated:YES];
    
    
    
    
    
}
@end
